<template>
  <div class="m-vplaylist">
    <div class="u-plhead">
      <div class="plhead_bg">
        <img
          :src="detailInfo.coverImgUrl"
          alt=""
        />
      </div>
      <div class="plhead_wrap">
        <div class="lsthd_fl">
          <img
            :src="detailInfo.coverImgUrl"
            alt=""
          />
          <span>歌单</span>
          <i></i>
        </div>
        <div class="plhead_fr">
          <h2>{{detailInfo.name}}</h2>
          <div>
            <div class="lsthd_ava">
              <img
                :src="authorInfo.avatarUrl"
                alt=""
              />
            </div>
            <span>{{authorInfo.nickname}}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="pylst_list">
      <h3>歌曲列表</h3>
      <div class="m-sglst">
        <song-list @play="$emit('play',$event)" :shownumber="true" v-if="detaiSong.length>0" :songlist="detaiSong"></song-list>
      </div>
      <div class="hot_comment" v-if="hotComment.length > 0">
        <h3>精彩评论</h3>
        <user-comment :comments="hotComment"></user-comment>
      </div>
      
      <div class="new_comment" v-if="newComment.length > 0">
        <h3>最新评论</h3>
        <user-comment :comments="newComment"></user-comment>
      </div>
    </div>
  </div>
</template>

<script>
import SongList from '@/components/SongList'
import UserComment from '@/components/UserComment'

export default {
  props: ["pid"],
  components:{
    SongList,
    UserComment
  },
  data() {
    return {
      playlist: [],
      detailInfo:{}, //歌单信息
      authorInfo:{}, //作者信息
      detaiSong:[], //歌单歌曲
      hotComment:[], //热门评论
      newComment:[], //最新评论
    };
  },
  created() {
    this.getPlayList();
    this.getComment();
  },
  beforeRouteEnter(to, from, next) {
    next();
  },
  methods: {
    async getPlayList() {
      let re = await this.axios.get("/playlist/detail?id=" + this.pid);
      this.detailInfo = re.playlist;
      this.authorInfo = re.playlist.creator;
      let detaiSong = re.playlist.tracks; 
            this.detaiSong =detaiSong.map((song,index)=>{
               song.song={
                 artists:song.ar,
                 privilege:re.privileges[index],
                 album:song.al
               } 
                return song;
            })
    },
    async getComment() {
      let re = await this.axios.get("/comment/playlist?id=" + this.pid);
      this.hotComment = re.hotComments;
      this.newComment = re.comments.slice(0,15);
    },
  },
};
</script>

<style lang="less">
.m-vplaylist {
  background-color: #fff;
  min-height: 100%;
  .u-plhead {
    position: relative;
    padding: 30px 10px 30px 15px;
    overflow: hidden;
    .plhead_bg {
      position: absolute;
      background-repeat: no-repeat;
      background-size: cover;
      background-position: 50%;
      filter: blur(20px);
      transform: scale(1.8);
    }
    .plhead_wrap {
      display: flex;
      position: relative;
      z-index: 2;
      .lsthd_fl {
        width: 126px;
        height: 126px;
        position: relative;
        background-color: #e2e2e3;
        img {
          width: 126px;
          vertical-align: middle;
        }
        span {
          position: absolute;
          z-index: 3;
          top: 10px;
          left: 0;
          padding: 0 8px;
          height: 17px;
          color: #fff;
          font-size: 9px;
          text-align: center;
          line-height: 17px;
          background-color: rgba(217, 48, 48, 0.8);
          border-top-right-radius: 17px;
          border-bottom-right-radius: 17px;
        }
        i {
          position: absolute;
          right: 2px;
          top: 0;
          z-index: 3;
          padding-left: 15px;
          color: #fff;
          font-size: 12px;
          background-position: 0;
          background-repeat: no-repeat;
          background-size: 11px 10px;
          text-shadow: 1px 0 0 rgb(0 0 0 / 15%);
        }
      }
      .plhead_fr {
        padding-left: 15px;
        h2 {
          padding-top: 1px;
          font-size: 17px;
          line-height: 1.3;
          color: #fefefe;
          height: 44px;
        }
        div {
          display: flex;
          align-items: center;
          margin-top: 4px;
          .lsthd_ava {
            display: block;
            width: 32px;
            height: 32px;
            img {
              width: 100%;
              border-radius: 50%;
            }
          }
          span {
            color: #fefefe;
            font-size: 14px;
            margin-left: 5px;
          }
        }
      }
    }
  }
  .pylst_list {
    padding-bottom: 70px;
    h3 {
      height: 23px;
      line-height: 23px;
      padding: 0 10px;
      font-size: 12px;
      color: #666;
      background-color: #eeeff0;
    }
  }
}
</style>